# 导库
from selenium import webdriver
import time
from selenium.webdriver.common.by import By

# (2)创建对象
wd = webdriver.Chrome()

# (3)访问网页
url = 'http://www.baidu.com'
# 访问方法：get()
wd.get(url)
time.sleep(2)

# 定位提取
#1.id定位
# element = wd.find_element(By.ID,'su')
# print(element.get_attribute('value'))
#2.name定位
# element = wd.find_element(By.NAME,'tn')
# print(element.get_attribute('value'))
#3.class:类名定位
# element = wd.find_element(By.CLASS_NAME,'s_btn')
# print(element.get_attribute('value'))
#4.tag_name:标签名
# element = wd.find_element(By.TAG_NAME,'input')#返回的是第一个input标签
# print(element.get_attribute('value'))
# elements = wd.find_elements(By.TAG_NAME,'input')
# # print(elements)
# for i in elements:
#     print(i.get_attribute('value'))

# 5.xpath:
# element = wd.find_element(By.XPATH,'//*[@id="su"]')
# print(element.get_attribute('value'))
# 6.css选择器
# element = wd.find_element(By.CSS_SELECTOR,'#su')
# print(element.get_attribute('value'))
#7.
# element = wd.find_element(By.LINK_TEXT,'新闻')
# print(element.text)
# print(element.get_attribute('href'))
element = wd.find_element(By.PARTIAL_LINK_TEXT,'新')
print(element.text)
print(element.get_attribute('href'))
element = wd.find_element(By.PARTIAL_LINK_TEXT,'12')
print(element.text)
print(element.get_attribute('href'))
wd.close()